<template>
    <div class="app-container" ref="appContainer">
      <el-card>
        <div class="card-box">
          <el-form :model="form">
            <el-form-item label="桌子ID">
              <el-input v-model="form.tableid" placeholder="">
              </el-input>
            </el-form-item>
            <el-form-item label="胜利0-100">
              <el-input v-model="form.rate" placeholder="">
              </el-input>
            </el-form-item>
            <el-form-item label="">
              <el-button type="primary" @click="handleSubmit()">控制胜率</el-button>
            </el-form-item>
          </el-form>
        </div>
      </el-card>
  
      <!-- ------------表格--------------->
  
      <div class="table">
  
        <el-table v-loading="loading" :data="list" fit highlight-current-row style="width: 100%" show-summary
          :border="true">
          <el-table-column label="桌子" align="center" prop="tableid" width="125px">
          </el-table-column>
          <el-table-column label="操作者" align="center" prop="operator" width="125px">
          </el-table-column>
          <el-table-column label="胜利 0-100" align="center" prop="rate" width="125px">
          </el-table-column>
          <el-table-column label="操作" align="center" width="500px">
          <template #default="scope">
            <el-button type="success" @click="onClickCancel(scope.row)">取消控制</el-button>
          </template>
        </el-table-column>
  
        </el-table>
  
      </div>
  
  
    </div>
  </template>
  <script lang="ts" setup name="comprehensive">
  import { GameConfig } from '@/config/GameConfig'
  import { HttpClient } from '@/utils/HttpClient'
  import { UIHelper } from '@/utils/UIHelper'
  import { now } from 'lodash'
  import { Search } from '@element-plus/icons-vue'
  import { ref, onMounted, reactive } from 'vue'
  import { Logger } from '@/engine/util/Logger'
  import { DateUtil } from '@/engine/util/DateUtil'
  
  let form = ref({ tableid: '1', rate: '0' })
  const loading = ref(false)
  let nowDate: Date = new Date()
  const selectDate = ref([
    new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate() - 1),
    new Date(nowDate.getFullYear(), nowDate.getMonth(), nowDate.getDate() + 1)
  ])
  
  let list = reactive([
    {
  
    }
  ])
  
  let handleSubmit = () => {
    if (form.value.tableid.length == 0) {
      UIHelper.showMsg("桌子不能为空")
      return
    }
    if (form.value.rate.length == 0) {
      UIHelper.showMsg("胜率不能为空")
      return
    }
    let rate: number = parseInt(form.value.rate)
    let tableid:number = parseInt(form.value.tableid)
    if (isNaN(rate)) {
      UIHelper.showMsg("胜利请输入数字")
      return
    }

    if (isNaN(tableid)) {
      UIHelper.showMsg("请输入桌子数字")
      return
    }
    HttpClient.set_yuxiaxie_rate(tableid, rate, ()=>{
        onclickSearch()
    })
    //   HttpClient.update_system_setting(GameConfig.System_Setting.customer, form.value.val, ()=>{
    //     UIHelper.showMsg("修改成功")
    //   })
  }
  
  onMounted(() => {
  
    onclickSearch()
  })
  
  const onclickSearch = () => {
    Logger.log("onclickSearch=", selectDate)
    // let startTime: number = Math.floor(selectDate.value[0].getTime() / 1000)
    // let endTime: number = Math.floor(selectDate.value[1].getTime() / 1000)
    HttpClient.get_yuxiaxie_rate((dataList: Array<object>) => {
      list.splice(0)
      for (let i = 0; i < dataList.length; i++) {
        let data: object = {
          "tableid": dataList[i]["tableid"],
          "operator": dataList[i]["operator"],
          "rate": dataList[i]["rate"],
        }
        list[i] = data
      }
  
    })
  }

  const onClickCancel = (row)=>{
    Logger.log("onClickCancel=", row)
    HttpClient.set_yuxiaxie_rate(row["tableid"], 0, ()=>{
        onclickSearch()
    })
  }
  
  </script>
          
  <style scoped lang="scss">
  .header {
    display: flex;
    padding: 16px 16px 0 16px;
    margin-bottom: 16px;
    border-radius: 4px;
    background: white;
    box-shadow: 0 0 12px rgb(0 0 0 / 5%);
  
    .search-form {
      flex: 1;
  
      ::v-deep {
        .el-input--default {
          width: 200px;
        }
      }
    }
  
    .search {
      flex-shrink: 0;
      white-space: nowrap;
    }
  }
  </style>
          